package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.LeaseSaleInformationPresenter
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.ui.fragment.CommonBaseFragment
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.LeaseSaleInformationView
import com.weetop.cfw.bean.MyLeaseSaleInformationListBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.mine.fragment.LeaseSaleInformationFragment
import com.weetop.cfw.utils.MMKVUtils
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class LeaseSaleInformationPresenterImp(var leaseSaleInformationView: LeaseSaleInformationView? = null): LeaseSaleInformationPresenter {
    /**
     * 获取我的出租出售信息列表数据
     */
    override fun getMyLeaseSaleInformationDataList(leaseSaleInformationFragment: CommonBaseFragment, status: Int, curpage: Int, pagesize: Int) {
        var tipMessage = ""
        tipMessage = when (status) {
            -1 -> {//全部出租出售信息
                "正在获取全部出租出售信息..."
            }
            1 -> {//待审核出租出售信息
                "正在获取待审核出租出售信息..."
            }
            else -> {//已发布出租出售信息
                "正在获取已发布出租出售信息..."
            }
        }
        leaseSaleInformationFragment.showLoadingDialog(leaseSaleInformationFragment.activity!! as CommonBaseActivity,tipMessage)
        val queryMap = HashMap<String,String>()
        queryMap["siteid"] = Constants.siteId.toString()
        queryMap["Token"] = MMKVUtils.getToken()
        queryMap["Status"] = status.toString()
        queryMap["Curpage"] = curpage.toString()
        queryMap["Pagesize"] = pagesize.toString()
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getMyRentalSaleListData(queryMap),leaseSaleInformationFragment,object:RxJavaCallBack<MyLeaseSaleInformationListBean>(){
            override fun onSuccess(t: MyLeaseSaleInformationListBean?) {
                leaseSaleInformationFragment.dismissLoadingDialog()
                 leaseSaleInformationView?.getMyLeaseSaleInformationSuccess(t)
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                leaseSaleInformationFragment.dismissLoadingDialog()
                leaseSaleInformationView?.getMyLeaseSaleInformationFailed()
            }

            override fun onRequestError(t: MyLeaseSaleInformationListBean?) {
                super.onRequestError(t)
                leaseSaleInformationFragment.dismissLoadingDialog()
                leaseSaleInformationView?.getMyLeaseSaleInformationFailed()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        leaseSaleInformationView = baseView as? LeaseSaleInformationView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       leaseSaleInformationView = null
    }
}